package net.lab1024.sa.admin.module.business.yct.ycttzq.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.yct.ycttzq.dao.UserProfileDao;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.entity.UserProfileEntity;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.form.UserProfileAddForm;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.form.UserProfileQueryForm;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.form.UserProfileUpdateForm;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.vo.UserProfileVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 听诊器用户成员 Service
 *
 * @Author zhangben
 * @Date 2024-10-10 13:24:57
 * @Copyright 20241010
 */

@Service
public class UserProfileService {

    @Resource
    private UserProfileDao userProfileDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<UserProfileVO> queryPage(UserProfileQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<UserProfileVO> list = userProfileDao.queryPage(page, queryForm);
        PageResult<UserProfileVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(UserProfileAddForm addForm) {
        UserProfileEntity userProfileEntity = SmartBeanUtil.copy(addForm, UserProfileEntity.class);
        userProfileDao.insert(userProfileEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(UserProfileUpdateForm updateForm) {
        UserProfileEntity userProfileEntity = SmartBeanUtil.copy(updateForm, UserProfileEntity.class);
        userProfileDao.updateById(userProfileEntity);
        return ResponseDTO.ok();
    }


    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        userProfileDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
